package GameStats;

import jHaggis.jHaggis;

import java.awt.Color;
import java.awt.Font;

import javax.swing.JEditorPane;
import javax.swing.JFrame;

import GameModel.mGame;
import GameStats.GameStats.PlayerStat;
import Player.mPlayer;
/**
 * @author Christopher Koller
 *
 */
public class vMainFrame extends jHaggis {

	/**
	*Startet das GUI
	*
	*@author Christopher Koller
	*/
	private static final long serialVersionUID = 1L;
	private String NumberOfRounds = new String("Number of Rounds");
	private String NumberOfTurns = new String("Number of Turns");
	private String Rank = new String("Rank");
	private String Points = new String("Points");
	private String BombsUsed = new String("Bombs used");
	private String HighestCombo = new String("Highest Combo");

	public vMainFrame(mGame game) {

		super("Game Statistics");
		GameStats GameStats = new GameStats(game);
		StringBuilder sb = new StringBuilder();

		sb.append("<!DOCTYPE html>");
		sb.append("<html style=\"font-family: Arial\">");
		sb.append("<head>");
		sb.append("<title>Game Statistics</title>");
		sb.append("<style type=\"text/css\">th { text-align:left; }</style>");
		sb.append("</head>");
		sb.append("<body style=\"font-family: Arial\">");
		sb.append("<div>");
		sb.append("<header>");
		if (GameStats.isWin()) {
			sb.append("<h1><font color=\"white\">You Win</font></h1>");
		} else {
			sb.append("<h1><font color=\"white\">You Lose</font></h1>");
		}
		sb.append("</header>");
		sb.append("<table>");
		sb.append("<tr>");
		sb.append("<th><font color=\"white\">" + NumberOfRounds + "</font></th>");
		sb.append("<td><font color=\"white\">" + GameStats.getValueNumberOfRounds() + "</font></td>");
		sb.append("</tr>");
		sb.append("<tr>");
		sb.append("<th><font color=\"white\">" + NumberOfTurns + "</font></th>");
		sb.append("<td><font color=\"white\">");
		sb.append(GameStats.getValueNumberOfTurns());
		sb.append("</font></td>");
		sb.append("</tr>");
		sb.append("<tr>");
		sb.append("<th><font color=\"white\">Nickname</font></th>");
		for (mPlayer player : game.getPlayers()) {
			sb.append("<th><font color=\"white\">" + player.getUserName() + "</font></th>");
		}
		sb.append("</tr>");
		sb.append("<tr>");
		sb.append("<th><font color=\"white\">" + Rank + "</font></th>");
		for (PlayerStat player : GameStats.getPlayers()) {
			sb.append("<td><font color=\"white\">" + player.getRank() + "</font></td>");
		}
		sb.append("</tr>");
		sb.append("<th><font color=\"white\">" + Points + "</font></th>");
		for (PlayerStat player : GameStats.getPlayers()) {
			sb.append("<td><font color=\"white\">" + player.getPoints() + "</font></td>");
		}
		sb.append("</tr>");
		sb.append("<tr>");
		sb.append("<th><font color=\"white\">" + BombsUsed + "</font></th>");
		for (PlayerStat player : GameStats.getPlayers()) {
			sb.append("<td><font color=\"white\">" + player.getBombs() + "</font></td>");
		}
		sb.append("</tr>");
		sb.append("<tr>");
		sb.append("<th><font color=\"white\">" + HighestCombo + "</font></th>");
		for (PlayerStat player : GameStats.getPlayers()) {
			sb.append("<td><font color=\"white\">" + player.getHighestCombo() + "</font></td>");
		}
		sb.append("</tr>");
		sb.append("</table>");
		sb.append("<footer>");
		sb.append("</footer>");
		sb.append("</div>");
		sb.append("</body>");
		sb.append("</html>");

		JEditorPane pane = new JEditorPane();
		pane.setEditable(false);
		pane.setContentType("text/html");
		pane.setText(sb.toString());
		pane.setOpaque(false);
		pane.setFont(new Font("Arial", Font.PLAIN, 14));
		pane.setForeground(Color.WHITE);

		add(pane);

		
		setSize(600, 330);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setVisible(true);
	}
}
